<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <link rel="icon" type="image/x-icon" th:href="${application.iconPath}"/>
    <div th:include="../templates/aaacommon/basic::html_header"></div>
    <title class="projectName"></title>
    <link th:href="@{{path}/istyle/css/login.css(path=${application.basePath}) }" rel="stylesheet" type="text/css"/>
    <style type="text/css">
    </style>
</head>
<body>

<div class="login">
    <div class="message projectName"></div>
    <div id="darkbannerwrap"></div>

    <form>
        <input id="account" name="account" placeholder="用户账号" required="" type="text" value=""/>
        <hr class="hr15"/>
        <input id="pwd" name="pwd" placeholder="密码" required="" type="password" value=""/>
        <hr class="hr15"/>
        <input value="登录" style="width: 100%;" type="button" id="sub"/>
        <hr class="hr20"/>
        帮助 <a href="javascript:void(0);" id="help">忘记密码</a>
    </form>
</div>

<div class="copyright">© 2018 sesame 软件</div>
<script type="text/javascript">
    layui.use(['element', 'form', 'layer', 'web', 'user'], function () {
        var element = layui.element;
        var form = layui.form;
        var layer = layui.layer;
        var web = layui.web;
        var user = layui.user;

        var redirect_url = getUrlParam("redirect_url");// 客户端回调的地址

        // 判断用户是否登录过
        var vif_login = false;
        web.load();
        var url = getRootPath_web() + "/user/verifyLogin";
        web.ajax_sync(url, 'post', {}, function (data) {
            var sessionId = data.result;
            if (sessionId != null && sessionId.length > 0) {
                vif_login = true;
            }
        });
        //如果已经登录,
        if(vif_login){
            // 如果有回调地址
            if (redirect_url != null && redirect_url.length > 0) {
                location.href = decodeURIComponent(redirect_url) + "?casId=" + sessionId;
            }else{
                location.href = basePath+"/index/index";
            }
        }


        $("#name").focus();
        $("#help").click(function () {
            layer.alert("请联系管理员", {
                icon: 6
            });
        });
        //键盘的监听事件
        $("#pwd").keyup(function () {
            if (event.keyCode == 13) {
                login();
            }
        });

        $("#sub").click(function () {
            login();
        });

        function login() {
            var account = $("#account").val();
            var pwd = $("#pwd").val();
            if (account == "") {
                layer.alert("请输入账号", {
                    icon: 2
                });
            } else if (pwd == "") {
                layer.alert("请输入密码", {
                    icon: 2
                });
            } else {
                web.load();
                var url = basePath + "/user/login";
                web.ajax(url, 'post', {account: account, pwd: pwd}, function (data) {
                    var sessionId = data.result;
                    if (redirect_url != null && redirect_url.length > 0) {
                        location.href = decodeURIComponent(redirect_url) + "?casId=" + sessionId;
                    } else {
                        location.href = basePath + "/index/index"
                    }

                });
            }
        }
    });
    $(".projectName").html(projectName);


    $("#account").val("admin");
    $("#pwd").val("123456");
</script>
</body>
</html>